package com.travel.controller;

import com.travel.common.Result;
import com.travel.service.SeckillVoucherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 秒杀优惠券控制器
 */
@RestController
@RequestMapping("/seckill")
public class SeckillVoucherController {

    @Autowired
    private SeckillVoucherService seckillVoucherService;

    /**
     * 秒杀操作
     * @param voucherId 秒杀优惠券ID
     * @param userId 用户ID
     * @return 秒杀结果
     */
    @PostMapping("/seckill/{voucherId}")
    public Result<String> seckillVoucher(@PathVariable Long voucherId, @RequestParam Long userId) {
        boolean result = seckillVoucherService.seckillVoucher(voucherId, userId);
        if (result) {
            return Result.success("秒杀成功");
        } else {
            return Result.error("秒杀失败，库存不足或已售罄");
        }
    }
}
